<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
     <%@ page import="java.util.*" %>
   <%@ page import="com.entity.Link"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="../show/css/bootstrap.css">
<style type="text/css">
	body {
		background-image: url("../show/images/pageturner.png");
	    background-repeat: no-repeat;
	}
	a{
		text-decoration: none;
	}
	a:visited {
		
		color: #0000EE;
	}
	.mytable{

    border:1px solid #A6C1E4;

    font-family:Arial;

    border-collapse: collapse;

}

    .mytable th{

    border:1px solid black;

    background-color:#71c1fb;

    width:100px;

    height:20px;

    font-size:15px;

}

    .mytable td{

    border:1px solid #A6C1E4;

    text-align:center;

    height:15px;

    padding-top:5px;

    font-size:12px;

}

 

.double{

    background-color:#c7dff6;

}
	</style>
</head>


<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">用户信息</h4>
            </div>
            <div class="modal-body">
                <table style="width: 475px;" border="1" align="center">
                    <tr>
                        <th>用户名</th>
                        <th>真实姓名</th>
                        <th>联系方式</th>
                        <th>用户身份</th>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<a  href="link/insertLink.jsp">添加链接</a> <input type="text" id="lkName"><button onclick="serc()">搜索</button>

<button data-toggle="modal" data-target="#myModal">用户信息</button>

<table class="mytable" width="1000" border="1" align="center">

<caption style="text-align: center"><b>链接信息</b></caption>

<tr>
<th>序号</th>
<th>链接描述</th>
<th>链接地址</th>
<th>存放位置</th>
<th>操作</th>
</tr>
</table>


</body>
<script src="../js/jquery.js"></script>
<script src="../js/bootstrap.js"></script>

<script>
    window.onload = function (ev) {
        $.ajax({
            url : "/sysLink/getlinklist",
            type : "post",
            dataType : "json",
            data : {},
            success:function (data) {
                for(i in data){
                    $(".mytable").
                    append('<tr class="double">' +
                        '<td>' + data[i].lkId + '</td>' +
                        '<td>' + data[i].lkName + ' </td>' +
                        '<td>' + data[i].lkUrl + '</td>' +
                        '<td>' + (data[i].lkPlace == 1 ? '顶部' : '底部') + '</td>' +
                        '<td>' +
                        '<a href="EditLinkServlet?id=' + data[i].lkId + '">编辑</a>||' +
                        '<a href="DeleteLinkServlet?id=' + data[i].lkId + '" onclick="return confirm(\'确定删除该链接吗？\');">删除</a>||' +
                        '<a  data-toggle="modal" data-target="#myModal" onclick="getauthor(' + data[i].lkId + ')">查看作者<a/>' +
                        '</td>' +
                        ' </tr>');
                }

            },
            error:function (e) {
                console.log(e);

            }
        })
    }

    function serc() {
        lkName = $("#lkName").val();
        console.log(lkName);
        $.ajax({
            url : "/sysLink/getlinklist",
            type : "post",
            dataType : "json",
            data : {
                "lkName" : lkName
            },
            success:function (data) {
                $(".mytable").find('.double').remove();


                for(i in data){
                    $(".mytable").
                    append('<tr class="double">' +
                        '<td>' + data[i].lkId + '</td>' +
                        '<td>' + data[i].lkName + ' </td>' +
                        '<td>' + data[i].lkUrl + '</td>' +
                        '<td>' + (data[i].lkPlace == 1 ? '顶部' : '底部') + '</td>' +
                        '<td>' +
                        '<a href="EditLinkServlet?id=' + data[i].lkId + '">编辑</a>||' +
                        '<a href="DeleteLinkServlet?id=' + data[i].lkId + '" onclick="return confirm(\'确定删除该链接吗？\');">删除</a>||' +
                        '<a  data-toggle="modal" data-target="#myModal" onclick="getauthor(' + data[i].lkId + ')">查看作者<a/>' +
                        '</td>' +
                        ' </tr>');
                }



            },
            error:function (e) {
                console.log(e);

            }
        })

    }

    function getauthor(lkId) {
        $.ajax({
            url : "/sysLink/getauthorauthor",
            data : {
                "lkId" : lkId
            },
            type : "post",
            success : function (data) {
                $(".modal-body").find("table").find(".cll").remove();
                $(".modal-body").find("table").append(
                    '<tr class="cll">' +
                    '<td>' + data.uname + '</td>' +
                    '<td>' + data.urname + ' </td>' +
                    '<td>' + data.uphone + '</td>' +
                    '<td>' + (data.ustatus == 0 ? '管理员' : (data.uStatus == 1 ? '编辑员' : '审核员')) + '</td>' +
                    '</tr>');
            }
        })
    }
</script>
</html>